export const debounce=(func: Function, time: number=500, immediate = false) =>{
    let timer: number | null = null;
    return (...args: any) => {
        if (timer) clearInterval(timer)
        if (immediate) {
            if (!timer) func.apply(this, args);
            timer = window.setTimeout(() => {
                timer = null
            }, time)
        } else {
            timer = window.setTimeout(() => {
                func.apply(this, args)
            }, time)
        }
    }
}

 
  export function throttle(func: (...args: any[]) => void, limit: number) {
    let inThrottle: boolean;
    return function (this: any, ...args: any[]) {
      if (!inThrottle) {
        func.apply(this, args);
        inThrottle = true;
        setTimeout(() => inThrottle = false, limit);
      }
    };
  }